package main;

import java.io.File;


public class WelfareRatioTableModel extends AbstractNItableModel {
	
	public float get_personal_social_security_ratio(String location) {
		return Float.valueOf((String) getValue(Constant.location,location,Constant.personal_social_security));
	}

	public float get_personal_housingfund_ratio(String location) {
		return Float.valueOf((String) getValue(Constant.location,location,Constant.personal_housingfund));
	}

	public float get_company_housingfund_ratio(String location) {
		return Float.valueOf((String) getValue(Constant.location,location,Constant.company_housingfund));
	}

	public float get_company_social_security_ratio(String location) {
		return Float.valueOf((String)  getValue(Constant.location,location,Constant.company_social_security));
	}

	public float get_toplimit_social_security(String location) {
		return Float.valueOf((String)  getValue(Constant.location,location,Constant.toplimit_social_security));
	}
	
	public float get_toplimit_housingfund(String location) {
		return Float.valueOf((String)  getValue(Constant.location,location,Constant.toplimit_houdingfund));
	}

	@Override
	public File createDataFile() {
		String filePath = System.getProperty("user.dir");
		return new File(filePath + "\\" + "welfareData.txt");
	}

/**
 * done
 */
	protected Object getValue(String indexCol_headerName, Object cellValue,
			String headValue) {
		int targetRow = -1;
		int indexCol=-1;
		for (int col=0;col<getColumnCount();col++) {
			if (getColumnName(col).equals(indexCol_headerName)) {
				indexCol=col;
				break;
			}
		}
		
		for (int row = 0; row < getRowCount(); row++) {
			Object value = getValueAt(row, indexCol);
			if (((String) value).equals((String)cellValue)) {
				targetRow = row;
				break;
			}
		}

		int targetCol = -1;
		
		for (int col=0;col<getColumnCount();col++) {
			if (getColumnName(col).equals(headValue)) {
				targetCol=col;
				break;
			}
		}

		return getValueAt(targetRow, targetCol);
	}

}
